if [[ ! -z $1 ]] && [[ -d $1 ]] && [[ -z ${unline_path} ]]
then
PREHOME=$1
elif [[ ! -z ${unline_path} ]]
then
PREHOME=${unline_path}
else
PREHOME=${HOME}"/unline"
fi
CURRENTPATH=$(readlink -f "$0")
DIR=$( dirname "$(readlink -f  ${CURRENTPATH})" )
which aria2c
if [[ $? -eq 1 ]]
then
  dockerstatus=$(sudo systemctl is-active docker)
  if [[ "$dockerstatus" == "active" ]]
  then
    sh ${DIR}/docker.sh
    exit 0
  else
    echo y | sudo apt-get install aria2
  fi
fi
if [[ ! -d /etc/aria2/ ]]
then
  sudo mkdir -p /etc/aria2
fi
if [[ ! -f /etc/aria2/aria2.session ]]
then
  sudo touch /etc/aria2/aria2.session
fi
sudo chmod 777 /etc/aria2/aria2.session
if [[ ! -f /etc/aria2/aria2.conf ]]
then
  sudo cp ${DIR}/template.conf /etc/aria2/aria2.conf
fi
if [[ ! -d ${HOME}/temp/crons ]]
then
  mkdir -p ${HOME}/temp/crons
fi
crontab -l 2>/dev/null | grep -E -v '^\s*#' | grep "check_aria2c.sh"
if [[ $? -eq 1 ]]
then
  echo 11
  conf_file=${HOME}/temp/crons/conf
  crontab -l 2>/dev/null > ${conf_file} && echo "*/15 * * * * ${DIR}/check_aria2c.sh">>${conf_file} && crontab ${conf_file} && rm -f ${conf_file}
fi
PARENTPATH=$(dirname ${DIR})
SOURCEFILE=`sh ${PARENTPATH}/getunlinefile.sh ${PREHOME} aria2ng`
if [[ -z $SOURCEFILE ]]
then
  if [[ ! -d ${PREHOME}/aria2ng ]]
  then
    mkdir -p ${PREHOME}/aria2ng
  fi
  wget -P ${PREHOME}/aria2ng https://github.com/mayswind/AriaNg/releases/download/1.3.7/AriaNg-1.3.7-AllInOne.zip 
  SOURCEFILE=`sh ${PARENTPATH}/getunlinefile.sh ${PREHOME} aria2ng`
fi
if [[ ! -d ${HOME}/temp/download/aria2ng ]]
then
  mkdir -p ${HOME}/temp/download/aria2ng
fi
unzip ${PREHOME}/aria2ng/${SOURCEFILE} -d ${HOME}/temp/download/aria2ng/
sudo cp -rvf ${HOME}/temp/download/aria2ng/index.html /etc/nginx/custom/
# https://blog.csdn.net/mzc11/article/details/81842534
# https://p3terx.com/archives/aria2-frontend-ariang-tutorial.html
